import request from "@/utils/request";
import type { CatgoryArr, Attrs, Attr } from "./type/index";
// 定义枚举类型
export enum API {
  // 获取一级菜单
  C1_URL = "/admin/product/getCategory1",
  // 获取二级菜单
  C2_URL = "/admin/product/getCategory2/",
  // 获取三级菜单
  C3_URL = "/admin/product/getCategory3/",
  // 获取所有的
  GETATTRLIST_URL = "/admin/product/attrInfoList/",
  // 添加新的数据
  ADDORUPDATEATTR_URL = "/admin/product/saveAttrInfo",
  // 删除一条数据
  DELETEATTR_URL = "/admin/product/deleteAttr/",
}
// 一级分类的接口
export const reqC1 = () => request.get<any, CatgoryArr>(API.C1_URL);
// 二级分类的接口
export const reqC2 = (category1Id: number | string) =>
  request.get<any, CatgoryArr>(API.C2_URL + category1Id);
// 三级分类的接口
export const reqC3 = (category2Id: number | string) =>
  request.get<any, CatgoryArr>(API.C3_URL + category2Id);
// 获取信息
export const reqAttrList = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string
) =>
  request.get<any, Attrs>(
    API.GETATTRLIST_URL + `${category1Id}/${category2Id}/${category3Id}`
  );
// 添加一条数据
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, Attr>(API.ADDORUPDATEATTR_URL, data);
// 删除一条数据
export const reqDeleteAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETEATTR_URL + attrId);
